package com.hz.ruoyistorage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hz.ruoyistorage.domain.LgColdSlot;
import com.hz.ruoyistorage.service.LgColdSlotService;
import com.hz.ruoyistorage.utils.ResultJSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0
 * @Author gj
 * @Date 2025/3/7 15:20
 * @注释
 */
@RestController
@RequestMapping("/slot")
public class LgColdSlotController {
    @Autowired
    private LgColdSlotService lgColdSlotService;
    //根据cold_id获得所有版位
    @GetMapping(value = "/{firstPart}")
    public ResultJSON getAllBySubId(@PathVariable Integer firstPart){
        return ResultJSON.success(lgColdSlotService.getBySubId(firstPart));
    }

    //添加版位
    @PostMapping("/addSlot")
    public ResultJSON addSlot(@RequestBody List<LgColdSlot> lgColdSlotList){
        System.out.println(lgColdSlotList);
        for (LgColdSlot lgColdSlot : lgColdSlotList){
            lgColdSlotService.addSlot(lgColdSlot);
        }
        return ResultJSON.success();
    }
    //减少板位
    @PostMapping("/delSlot")
    public ResultJSON delSlot(@RequestBody List<LgColdSlot> lgColdSlotList){
        for (LgColdSlot lgColdSlot : lgColdSlotList){
            QueryWrapper<LgColdSlot> queryWrapper = new QueryWrapper<>();
            //判断哪个小冷库
            queryWrapper.eq("sub_id",lgColdSlotList.get(0).getSubId());
            queryWrapper.eq("slot_name",lgColdSlot.getSlotName());
            lgColdSlotService.remove(queryWrapper);
        }
        return ResultJSON.success();
    }
}
